var isnotfirstlogin;
var storage = window.localStorage;
//#95e095
$(function(){
	if(dianhua!=""){
		$("#phone").val(dianhua);
	}
	/*$("#bmiBox").show();*/
});

function toSave(){
		var $loadingToast = $('#loadingToast');
		if ($loadingToast.css('display') != 'none') {
			return;
		}
		$loadingToast.show();
		var url=basePath+"user/login.spring";
		var phone=$("#phone").val();
		var psw=$("#psw").val();
			if(phone==""){
				alert("请输入手机号码");
			}else if(psw==""){
				alert("请输入密码");
			}else{
		$.ajax({
		　　	url : url,
		　　	data : {"phone":phone,"psw":psw},
		　　	type : "POST",
		  	dataType : 'json',
		　　	success : function(data) {
				if(data.resultCode==0){

					storage.setItem("flag", true);
					storage.setItem("primaryRole",data.content.userCode);
					storage.setItem("primaryRoleName",data.content.userName);
					storage.setItem("currentName",data.content.realName);
					storage.setItem("currentRole",data.content.userCode);
					storage.setItem("isMainRole",1);
					
/*	           	    var now = getSmpFormatNowDate(false);
	           	    var birth = getSmpFormatDateByLong(data.content.birth,false);
	           	    var age = DateDiff(now,birth);//多少天 
*/					var age = data.content.day;
           	      	storage.setItem("curSex",data.content.sex);
           	      	storage.setItem("curage",age);
           	      	storage.setItem("curAgeFlag",dayToAgeFlag(age)); 
					
					if(iswx==1){
						 var  turl="./jsp/asking_ai.jsp?iswx=1";

						 window.location.href=turl; 
						 return;
					 }
					//请求返回亲情账号
					if(data.isnotfirstlogin==0){
						setTimeout(function() {
							$loadingToast.hide();
							$("#toast").show();
							setTimeout(function() {
								$("#toast").hide();
								 window.location.href = basePath+"jsp/userInfo.jsp";
								   isnotfirstlogin=data.isnotfirstlogin;
							}, 1000);
						}, 1000);
			
					}else {
						setTimeout(function() {
							$loadingToast.hide();
							$("#toast").show();
							setTimeout(function() {
								$("#toast").hide();
								  isnotfirstlogin=data.isnotfirstlogin;
								  /*window.location.href = basePath+"jsp/index.jsp"; */
								  showbmiBox();
							}, 1000);
						}, 1000);
		  
					}
					
				}else {
					 setTimeout(function() {
							$loadingToast.hide();
						}, 1000);
					
					window.location.reload();
				}
				alert(data.msg);
		　　}
		});
	}
}

function jump(){
	window.location.href = basePath+"jsp/index.jsp";
}

function pop(){
    var w_height = $(window).height();
    $('.leftmenu').css('height',w_height);
    //   弹出边菜单
    $('.leftmenu,.bg_mark').css('display','block');
    $('.leftmenu .leftmenu_con ' ).stop().animate({ left: '0' }, 400);
    $('.cancle').click(function(){
    	  $('.leftmenu').css('height',w_height);
        $('.leftmenu .leftmenu_con ').stop().animate({ left: '-100%' }, 400);
        setTimeout(function(){
            $('.leftmenu,.bg_mark').fadeOut('fast');
        },200);
    });
}
//前往注册页面
function toRegister(){
	window.location.href = basePath+"jsp/register.jsp";
}

function tijiao(){
		
	var w_height = $(window).height();
	var val=$("input[name='radio1']:checked").val();
	$.ajax({
       url: basePath+"user/currRole.spring",
       type: "POST",
       data:{currRole:val},
       dataType: 'json',
       cache: false,
       success: function (ret) {
    	   if (ret.resultCode==0) {
			   $('.leftmenu').css('height',w_height);
			   $('.leftmenu .leftmenu_con ').stop().animate({ left: '-100%' }, 400);
			   setTimeout(function(){
				   $('.leftmenu,.bg_mark').fadeOut('fast');
			   },200);
			   if(iswx==1){
				   var  turl=basePath+"inquiry/toSelfTest.spring?iswx=1";
				   window.location.href=turl; 
				   return;
			   }else{
				   if(isnotfirstlogin==1){//不是第一次登录
					   window.location.href = basePath+"jsp/index.jsp";
				   }else{//第一次登录
					   window.location.href = basePath+"jsp/userInfo.jsp";
				   }
			   }
          }
           
       }
   });
	  
}

/**
 * 忘记密码
 * @returns
 */
function  forgetPsw(){ 
	var phone=$("#phone").val();
	var url;
	if(phone!=""){
	 url=basePath+"jsp/alterPsw.jsp?phone="+phone;
	}else{
		url=basePath+"jsp/alterPsw.jsp";	
	}
	 window.location.href =url;
	
}